﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraFollow : MonoBehaviour {

    public GameObject target;
    public float smoothSpeed;
    public Vector2 rangeX;
    public Vector2 rangeY;
    public Vector3 offset;
	// Use this for initialization
	void Start () {
      
	}
	
	// Update is called once per frame
	void Update () {

        Vector3 des = target.transform.position + offset;
        if (des.x < rangeX.x)
            des.x = rangeX.x;
        if (des.x > rangeX.y)
            des.x = rangeX.y;
        if (des.y < rangeY.x)
            des.y = rangeY.x;
        if (des.y > rangeY.y)
            des.y = rangeY.y;
        transform.position = Vector3.Lerp(transform.position, des, smoothSpeed * Time.deltaTime);
	}
}
